package com.supersit.greensproject.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.amap.api.maps2d.model.Text;
import com.supersit.greensproject.R;
import com.supersit.greensproject.entity.MaketSubject;

import java.util.List;

/**
 * Created by cong on 2016/7/13.
 */
public class MaketSubjectDataAdapter extends BaseAdapter {
    private Context context;
    private List<MaketSubject> data;
    private LayoutInflater inflater;

    public MaketSubjectDataAdapter(Context context, List<MaketSubject> data) {
        this.context = context;
        this.data = data;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return data == null ? 0 : data.size();
    }

    @Override
    public Object getItem(int position) {
        return data == null ? null : data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        HolderView holderView;
        if (null == convertView) {
            holderView = new HolderView();
            convertView = inflater.inflate(R.layout.item_maket_list, null);
            holderView
                    .tvmaketName = (TextView) convertView.findViewById(R.id.tv_base_Name);
            holderView.tvarea = (TextView) convertView.findViewById(R.id.tv_area);
            holderView.tvcreateDate = (TextView) convertView.findViewById(R.id.tv_create_date);
            holderView.tvMaketType = (TextView) convertView.findViewById(R.id.tv_maket_type);
            holderView.isDelete = (ImageView) convertView.findViewById(R.id.iv_is_delete);
            convertView.setTag(holderView);
        } else {
            holderView = (HolderView) convertView
                    .getTag();
        }
        holderView.tvmaketName.setText(data.get(position).getMaketName() == null ? "" : data.get(position).getMaketName());
        holderView.tvarea.setText(context.getResources().getStringArray(R.array.area)[data.get(position).getAreaId()]);
        holderView.tvcreateDate.setText(data.get(position).getCreateDate() == null ? "" : data.get(position).getCreateDate());
        holderView.tvMaketType.setText(context.getResources().getStringArray(R.array.maket_type)[data.get(position).getCategory()]);
        if (data.get(position).getOperationsTatus() == 0) {
            holderView.isDelete.setVisibility(View.VISIBLE);
        } else {
            holderView.isDelete.setVisibility(View.GONE);
        }
        return convertView;
    }

    class HolderView {
        TextView tvmaketName;
        TextView tvarea;
        TextView tvcreateDate;
        TextView tvMaketType;
        ImageView isDelete;
    }

    public void setData(List<MaketSubject> data) {
        this.data = data;
    }
}
